<?php

function smarty_function_render( $p, Smarty &$smarty )
{
	if( !isset( $p['t'] ) ) return '';
	
	$url = @parse_url( $p['t'] ); unset( $p['t'] );
	if( !$url ) return '';
	
	$assign = ( isset( $p['assign'] ) && $p['assign'] ) ? $p['assign'] : null;
	$append = ( isset( $p['append'] ) && $p['append'] ) ? $p['append'] : null;

	bc::log( $url );
	
	switch( $url['scheme'] )
	{
	
	case 'config':
	$tpl = str_replace( array( '//', '/' ), '__', str_replace( array( '//', "\\\\", "\\" ), '/', trim($url['host'].$url['path'],'/\\') ) );
	$tpl = config::instance( ) ->$tpl;
	$_i = 0;
	foreach( $p as $_k => $_v )
	{
		$_i ++; $_c = '%'.$_i.'$';
		$tpl = str_replace( array( "{s:{$_k}}", "{{$_k}}", "{i:{$_k}}" ), array( "{$_c}s", "{$_c}s", "{$_c}d" ), $tpl );
	}
	$_r = vsprintf( $tpl, array_values( $p ) );
	break;
	
	default:
	$_r = '{unsupported renderer '.$url['scheme'].'}';
	}
	
	if( !is_null( $assign ) ) { $smarty ->assign( $assign, $_r ); }
	elseif( !is_null( $append ) ) { $smarty ->append( $append, $_r ); }
	else { return $_r; }
}



?>